package com.qfedu.aunt.commons.auth.security;

import com.qfedu.aunt.commons.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 这个类是使用自己的密码的散列类来进行密码的散列
 * 和密码的比较
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    public DefaultPasswordEncoder() {
        this(-1);
    }
    public DefaultPasswordEncoder(int strength) {
    }
    //进行MD5加密
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.encrypt(charSequence.toString());
    }
    //进行密码比对
    @Override
    public boolean matches(CharSequence charSequence, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(charSequence.toString()));
    }


    public static void main(String[] args){
        String encrypt = MD5.encrypt("123456");
        System.out.println("密码是:"+encrypt);
    }
}
